var class_num=location.search;
class_num=class_num.split('?')[1];
$('#href_index').attr('href','course.html?'+class_num);
$('#href_message').attr('href','message.html?'+class_num);
$('#me').attr('href','me.html?'+class_num);
if (islogin()) {
    $('#op').click(function () {
        var btn1=[
            {
                text:'给老师留言',
                onClick:function () {
                    window.location.href='add_message.html?'+class_num;
                }
            }
        ];
        var btn2=[
            {
                text:'取消'
            }
        ];
        var groups=[btn1,btn2];
        $$.actions(groups);
    });

    $.post({
        url:'../../requests/student/select_leavemessage.php',
        async:false,
        data:{"class":class_num},
        success:function (data) {
            console.log(data);
            for (var i = 0; i < data.length; i++) {
                if (data[i].reply) {
                    var dom =" <div class=\"content-block-title\"></div>\n"+
                    "                <div class=\"card\">\n" +
                        "                    <div class=\"card-header\">标题:"+data[i].title+"</div>\n" +
                        "                    <div class=\"card-content\">\n" +
                        "                        <div class=\"card-content-inner\">\n" + data[i].detail+
                        "                        </div>\n" +
                        "</div>\n" +
                        "                        <div class=\"card-footer\">\n" +
                        "                            <span>"+data[i].time+"</span>\n" +
                        "                            <span><button class=\"button disabled\">已回复</button></span>\n" +
                        "                        </div>\n" +
                        "                </div>\n" +
                        "                <div class=\"card\">\n" +
                        "                    <div class=\"card-header\">回复内容</div>\n" +
                        "                    <div class=\"card-content\">\n" +
                        "                        <div class=\"card-content-inner\">"+data[i].reply+"</div>\n" +
                        "                    </div>\n" +
                        "                    <div class=\"card-footer\">\n" +
                        "                        <span>"+data[i].re_time+"</span>\n" +
                        "                    </div>\n" +
                        "                </div>";
                }
                else {
                    var dom=" <div class=\"content-block-title\"></div>\n" +
                        "                <div class=\"card\">\n" +
                        "                    <div class=\"card-header\">标题:"+data[i].title+"</div>\n" +
                        "                    <div class=\"card-content\">\n" +
                        "                        <div class=\"card-content-inner\">\n" + data[i].detail+
                        "                        </div>\n" +
                        "                    </div>\n" +
                        "                    <div class=\"card-footer\">\n" +
                        "                        <span>"+data[i].time+"</span>\n" +
                        "                        <span><button class=\"button disabled btn_reply btn_"+data[i].Id+"\">未回复</button></span>\n" +
                        "                    </div>\n" +
                        "                </div>\n"
                }
                $('.cards-list').append(dom);
            }
        }
    });
}
else window.location.href='../../index.html';